package com.salton123.groupbargain.ui.fm

import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import com.salton123.groupbargain.R
import com.salton123.groupbargain.model.BannerEntity
import com.salton123.groupbargain.ui.adapter.UltraPagerAdapter
import com.salton123.ui.base.BaseFragment
import com.salton123.ui.base.LifeDelegateFragment
import com.salton123.util.ScreenUtils
import com.tmall.ultraviewpager.UltraViewPager
import java.util.ArrayList

class HomeComp : BaseFragment() {
    private var adapter: UltraPagerAdapter? = null
    private lateinit var ultraViewPager: UltraViewPager
    override fun getLayout(): Int = R.layout.comp_home

    override fun initVariable(savedInstanceState: Bundle?) {

    }

    override fun initViewAndData() {
        ultraViewPager = f(R.id.banner)
        val tempList = ArrayList<BannerEntity>()
        tempList.add(BannerEntity(R.drawable.banner_daily))
        tempList.add(BannerEntity(R.drawable.banner_remove_ads))
        adapter = UltraPagerAdapter(tempList)
        ultraViewPager.setAdapter(adapter)
        ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL)
        ultraViewPager.setMultiScreen(0.8f)
        // ultraViewPager.setAutoMeasureHeight(true);
        // ultraViewPager.setPageTransformer(false, new UltraScaleTransformer());
        ultraViewPager.initIndicator()
        //set style of indicators
        ultraViewPager.getIndicator()
            .setOrientation(UltraViewPager.Orientation.HORIZONTAL)
            .setFocusColor(Color.WHITE)
            .setNormalColor(Color.parseColor("#99FFFFFF"))
            .setMargin(0, 0, 0, ScreenUtils.dp2px(20f))
            .setRadius(ScreenUtils.dp2px(3f))
        //set the alignment
        ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM)
        //construct built-in indicator, and add it to  UltraViewPager
        ultraViewPager.getIndicator().build()
        //set an infinite loop
        ultraViewPager.setInfiniteLoop(true)
        //enable auto-scroll mode
        ultraViewPager.setAutoScroll(5000)
    }

    override fun isOpenMultiStatus(): Boolean {
        return false
    }
}
